
#include <stdint.h>
#include "driver/i2c_master.h"

#define READ_ADDR                  0x81	 //A0=GND，A1=GND // R=1, W=0
#define WRITE_ADDR                 0x80

#define Config_Reg                 0x00   //配置寄存器  读写
#define Shunt_V_Reg                0x01   //分流电压    读
#define Bus_V_Reg                  0x02   //总线电压    读
#define Power_Reg                  0x03   //电源 读
#define Current_Reg                0x04   //电流 读
#define Calib_Reg                  0x05   //校准寄存器 读写
#define Mask_En_Reg                0x06   
#define Alert_Reg                  0x07
#define Man_ID_Reg                 0xFE  //0x5449
#define ID_Reg                     0xFF  //0x2260

class Ina226{
public:
    Ina226(i2c_port_t i2c_master_port, int sda_io, int scl_io);
    void INA226_Init(void);
    float INA226_GetVoltage(void);//获取总线电压mV
    float INA226_GetShunt_Current(void);//获取分流电流mA
    float Curent;
    float Voltage;
private:
    i2c_port_t ina_port;
    int sda_io_num;
    int scl_io_num;
    float rnf = 1.0f/1e-2;
    void INA226_Read2Byte(uint8_t reg_addr, uint16_t *reg_data);
    void INA226_Write2Byte(uint8_t reg_addr,uint16_t reg_data);
};
